# -*- coding: utf-8 -*- 
# @project : 《Atcoder》
# @Author : created by bensonrachel on 2021/11/20
# @File : 228.B - Takahashi's Secret.py
n,x = map(int,input().split())
a = [0]+list(map(int,input().split()))
cnt = 0
tag = [0]*(n+1)
n = n+1
while(n):
    tag[x] = 1
    x = a[x]
    n -=1
print(sum(tag))